package abc;
import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.awt.*;


public class YingYongDuoKai{
    public static void main(String[] main){
        try{
            String s = "";
            int num = 0;

            System.out.println("请输入您的应用运行文件（.exe）的路径：");
            System.out.println("输入的时候一定要加上引号，否则会被识别为打开文件夹。");
            System.out.println("只支持微信等没有“启动.exe“的应用");
            Scanner path = new Scanner(System.in);
            s = path.nextLine();
            System.out.println("请输入您要打开的应用数量：");
            Scanner num1 = new Scanner(System.in);
            num =Integer.parseInt(num1.nextLine());

            Runtime runtime = Runtime.getRuntime();
            //System.out.println(baseCmd);
            runtime.exec("cmd /c " + open(s,num));
            runtime.exit(0);
            //startProgram(num);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    /**
     *方法1
     * 启动应用程序
     *
     */
    public static void startProgram(int num) {
        String programPath="E:\\微信\\WeChat\\WeChat.exe";
        try {
            for(int i=1;i<=num;i++){
                Desktop.getDesktop().open(new File(programPath));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *方法2
     *命令字符串拼接
     */
    public static String open(String s,int num) throws IOException{
        String s1 = "@echo off"+'\n';
        String s2 = "exit";
        String s3 = "";
        s3 = "&start "+'\"'+'\"'+' '+'\"'+s+'\"';
        String s4 = "";

        //System.out.println(s1);
        for(int i=0;i<num;i++){
            s4+=s3+'\n';
        }
        return(s1+s4+s2);
    }
}